package com.czkt.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController {

    @GetMapping("/")
    public String index(){
        return "login";
    }
    @RequestMapping("/403")
    public String authError(){
        return "403";
    }





    @RequestMapping("/index")
    public Object index(Model model, HttpSession session){
        model.addAttribute("userName","<span style='color:red;'>李杰</span>");
        model.addAttribute("color","red");
        model.addAttribute("currentTime",new Date());
        model.addAttribute("price","1899");
        model.addAttribute("imagePath","https://e-assets.gitee.com/gitee-community-web/_next/static/media/bg.5ab8baa5.jpg");

        Map userMap = new HashMap<>();
        userMap.put("userName","张峥嵘");
        userMap.put("age","20");
        model.addAttribute("user",userMap);
        session.setAttribute("userName","张峥嵘");

        return "demo/index";
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(){
        return "添加成功";
    }
}
